package org.redmagic.utils;

import java.io.FileInputStream;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public final class DocumentLoader {

    private DocumentLoader() {
        
    }
    
    public static Document load(String fileName) {
        return load(fileName, false);
    }
    
    public static Document load(String fileName, boolean namespaceAware) {
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(fileName);
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(namespaceAware);
            DocumentBuilder docBuilder = factory.newDocumentBuilder();
            Document document = docBuilder.parse(inputStream);
            return document;
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
